<?php
/* ========== ########## ========== ########## ========== ########## ========== */
/*                                                                              */
/*   WHMCS v4.1.2 NULLED R4 by FLIPMODE  [ BAD SYNTAX ]                         */
/*                                                                              */
/*                             INTERNAL BAD SYNTAX NULLED VERSION: 2.5.9.6 R4   */
/*                                                                              */
/*   ALL files have been analysed, cleaned and nulled of:                       */
/*     - Call Backs  (100%)                                                     */
/*     - Link Backs (95%)                                                       */
/*     - Licensing  (100%)                                                      */
/*     - Remote Links + URL's                                                   */
/*                                                                              */
/*   WHMCS v4.1.2 RELEASED: 4th November 2009                                   */
/*    -> FIRST v4.1.2 NULL R1: 19th November 2009                               */
/*    -> UPDATED v4.1.2 NULL R4: 27th November 2009                             */
/*                                                                              */
/*   TESTING + VERIFICATION::                                                   */
/*     Files Cleaned, Nulled, Checked, Verified By:                             */
/*      -> FLIPMODE!                                                            */
/*     Decoded By:                                                              */
/*      -> FLIPMODE! + Unknown Decoder                                          */
/*     Tested By:                                                               */
/*      -> FLIPMODE!, LeetWolf, and 12 Anonymous Users...                       */
/*     WHMCS 4.1.2 Supplied By:                                                 */
/*      -> WHM CompleteShit Coder @ WHMCS.com                                   */
/*                                                                              */
/*                                                                              */
/*   IMPORTANT NOTE::                                                           */
/*   PLEASE NOTE THIS IS FOR TRIAL PURPOSES ONLY!                               */
/*                          LIKE IT? THEN BUY IT!                               */
/*                                                                              */
/* ========== ########## ========== ########## ========== ########## ========== */


include '../dbconnect.php';
include '../includes/functions.php';
session_regenerate_id ();
$result = select_query ('tbladmins', 'id,username,password', array ('username' => $username));
$data = mysql_fetch_array ($result);
$login_uid = $data['id'];
$login_unm = $data['username'];
$login_pwd = $data['password'];
if (($login_uid AND md5 ($password) === $login_pwd))
{
	$_SESSION['adminloggedinstatus'] = 'true';
	$_SESSION['adminid'] = $login_uid;
	if ($CONFIG['DisableSessionIPCheck'])
	{
		$haship = '';
	}
	else
	{
		$haship = $remote_ip;
	}

	$_SESSION['adminpw'] = md5 ($login_uid . $login_pwd . $haship);
	update_query ('tbladminlog', array ('logouttime' => 'now()'), array ('adminusername ' => $login_unm, 'logouttime' => '00000000000000'));
	insert_query ('tbladminlog', array ('adminusername' => $login_unm, 'logintime' => 'now()', 'ipaddress' => $remote_ip, 'sessionid' => session_id ()));
	update_query ('tbladmins', array ('loginattempts' => '0'), array ('username' => $login_unm));
	if ($rememberme)
	{
		setcookie ('WHMCSAdminID', $login_uid, time () + 60 * 60 * 24 * 365);
		setcookie ('WHMCSAdminPW', $_SESSION['adminpw'], time () + 60 * 60 * 24 * 365);
	}
	else
	{
		setcookie ('WHMCSAdminID', '');
		setcookie ('WHMCSAdminPW', '');
	}

	header ('Location: index.php');
	exit ();
}

if ($login_unm)
{
	$result = update_query ('tbladmins', array ('loginattempts' => '+1'), array ('username' => $login_unm));
	$result = select_query ('tbladmins', 'loginattempts', array ('username' => $login_unm));
	$data = mysql_fetch_array ($result);
	$loginattempts = $data['loginattempts'];
	if ('3' <= $loginattempts)
	{
		$expire_date = mktime (date ('H'), date ('i') + $CONFIG['InvalidLoginBanLength'], date ('s'), date ('m'), date ('d'), date ('Y'));
		$expire_date = date ('Y-m-d H:i:s', $expire_date);
		insert_query ('tblbannedips', array ('ip' => $remote_ip, 'reason' => '3 Invalid Login Attempts', 'expires' => $new_date));
		insert_query ('tblbannedips', array ('ip' => $remote_ip, 'reason' => '3 Invalid Login Attempts', 'expires' => $expire_date));
		update_query ('tbladmins', array ('loginattempts' => '0'), array ('username' => $loginusername));
	}
}

sendadminnotification ('system', 'Admin Failed Login Attempt', '<p>A recent login attempt failed.  Details of the attempt are below.</p><p>Date/Time: ' . date ('d/m/Y H:i:s') . ('' . '<br>Username: ' . $username . '<br>IP Address: ' . $remote_ip . '<br>Hostname: ') . gethostbyaddr ($remote_ip) . '</p>');
header ('Location: login.php?func=incorrect');
?>